<?php
namespace Common\Behaviors;
class LoginBehavior extends \Think\Behavior
{
    //单点行为行为执行入口
    public function run(&$param)
    {
        $box_login_code = I('box_login_code');
        if (!$box_login_code) {
            return;
        }
        if (session('user_id')) {
            return;
        }
        $user_info = $this->getUserInfo($box_login_code);
        if ($user_id = $user_info['user_id']) {
            Logic("BoxSns", "Member")->saveLogin($user_id);  //在自己网站也登录一下
        }

    }


    protected function getUserInfo($code)
    {
        $url = LoginUrl . "/BoxApi/Index/auth_info/box_login_code/" . $code;
        $data = mycurl($url);
        $user_info = json_decode($data, true);
        return $user_info;
    }


}
